package com.onstar.cn.weight;

import android.graphics.drawable.Drawable;
import android.view.View;

/**
 * 单个图层
 * 
 * @author cwjtojava
 * 
 */
public class TouchViewLayer {

	/**
	 * 图层自生成编号
	 */
	private int layerCount = 0;

	/**
	 * 层名称
	 */
	private String layerName;

	/**
	 * 正常实现的图片
	 */
	private Drawable drawableNormal;

	/**
	 * 点击后的图片
	 */
	private Drawable drawableDown;

	/**
	 * 此颜色的像素点点击无效
	 */
	private int maskColor;

	/**
	 * 点击监听器
	 */
	private View.OnClickListener onClickListener;

	/**
	 * 是否可以被点击并响应事件
	 */
	private boolean clickable;

	/**
	 * 默认图层名称前缀
	 */
	private final String DEFAULT_LAYER_NAME_PREFIX = "layer";

	/**
	 * 默认遮罩色
	 */
	private final static int DEFAULT_MASKCOLOR = 0x00000000;

	public TouchViewLayer() {

	}

	/**
	 * 构造图层
	 * 
	 * @param layerName
	 *            图层名称
	 * @param drawableNormal
	 *            普通情况下显示的图片
	 * @param drawableDown
	 *            点击后显示的图片
	 * @param maskColor
	 *            遮罩色（点击点的颜色如果为遮罩色则判断为没有点击）
	 * @param onClickListener
	 *            点击响应事件
	 * @param clickable
	 *            是否可以被点击并响应点击事件
	 */
	public TouchViewLayer(String layerName, Drawable drawableNormal, Drawable drawableDown, int maskColor,
			View.OnClickListener onClickListener, boolean clickable) {

		this.layerName = layerName;
		this.drawableNormal = drawableNormal;
		this.drawableDown = drawableDown;
		this.maskColor = maskColor;
		this.onClickListener = onClickListener;
		this.clickable = clickable;
	}

	/**
	 * 构造图层<br>
	 * 一般图层推荐使用该方法，默认图层名称、遮罩色为透明色、可以接受点击响应
	 * 
	 * @param context
	 *            系统上下文关系
	 * @param drawableNormal
	 *            普通图片效果
	 * @param drawableDown
	 *            点击图片效果
	 * @param onClickListener
	 *            点击响应
	 */
	public TouchViewLayer(Drawable drawableNormal, Drawable drawableDown, View.OnClickListener onClickListener) {
		this(null, drawableNormal, drawableDown, DEFAULT_MASKCOLOR, onClickListener, true);

		layerName = generateLayerName();
	}

	/**
	 * 构造图层<br>
	 * 仅显示用图层推荐使用该方法，默认图层名称、遮罩色为透明色、不可以接受点击响应
	 * 
	 * @param drawableNormal
	 *            普通图片效果
	 */
	public TouchViewLayer(Drawable drawableNormal) {
		this(null, drawableNormal, null, DEFAULT_MASKCOLOR, null, false);
		layerName = generateLayerName();
	}

	/**
	 * 构造图层<br>
	 * 外部控制图层显示推荐使用该方法，默认遮罩色为透明，不可以接受点击响应
	 * 
	 * @param layerName
	 *            图层名称
	 * @param drawableNormal
	 *            普通图片效果
	 * @param drawableDown
	 *            点击图片效果
	 */
	public TouchViewLayer(String layerName, Drawable drawableNormal, Drawable drawableDown) {
		this.layerName = layerName;
		this.drawableNormal = drawableNormal;
		this.drawableDown = drawableDown;
		this.maskColor = DEFAULT_MASKCOLOR;
		this.onClickListener = null;
		this.clickable = false;
	}

	public String getLayerName() {
		return layerName;
	}

	public void setLayerName(String layerName) {
		this.layerName = layerName;
	}

	public Drawable getDrawableNormal() {
		return drawableNormal;
	}

	public void setDrawableNormal(Drawable drawableNormal) {
		this.drawableNormal = drawableNormal;
	}

	public Drawable getDrawableDown() {
		return drawableDown;
	}

	public void setDrawableDown(Drawable drawableDown) {
		this.drawableDown = drawableDown;
	}

	public int getMaskColor() {
		return maskColor;
	}

	public void setMaskColor(int maskColor) {
		this.maskColor = maskColor;
	}

	public View.OnClickListener getOnClickListener() {
		return onClickListener;
	}

	public void setOnClickListener(View.OnClickListener onClickListener) {
		this.onClickListener = onClickListener;
	}

	public boolean isClickable() {
		return clickable;
	}

	public void setClickable(boolean clickable) {
		this.clickable = clickable;
	}

	/**
	 * 生成默认层名称
	 * 
	 * @return
	 */
	private String generateLayerName() {
		return DEFAULT_LAYER_NAME_PREFIX + layerCount++;
	}
}
